<template>
	<view class="content">
		<u-navbar title="设置微信" :border-bottom="false" back-icon-color="#ffffff" title-color="#fff" :background="{backgroundColor:'#2A2931'}"></u-navbar>
<!-- 		<view class="fieldbox">
			<u-field
				v-model="name"
				label="真实姓名"
				placeholder="请填写认证真实姓名"
				label-width="180"
				:border-bottom="false"
			>
			</u-field>
			<u-field
				v-model="account"
				label="微信账号"
				placeholder="请填写微信账号"
				label-width="180"
				:border-bottom="false"
			>
			</u-field>
			<u-field
				v-model="code"
				label="验证码"
				placeholder="请填写验证码"
				label-width="180"
				:border-bottom="false"
			>
				<u-button size="mini" slot="right" type="success" @click="getCode">{{codeText}}</u-button>
			</u-field>
			<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
		</view>
		<button class="new-btn" @click="save">保存</button> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'',
				account:'',
				code:'',
				codeText: '发送验证码',
				phone: '',
				yzPhone: '',
				yzCode: ''
			}
		},
		onLoad() {
			this.phone = this.$store.state.userinfo.phone
		},
		methods: {
			async save(){
				var phone = this.phone
				var code = this.code
				var aliName = this.name
				var aliNum = this.account
				if (!aliName) {
					this.$u.toast('名字未填写');
					return;
				}
				if (!aliNum) {
					this.$u.toast('微信账号未填写');
					return;
				}
				if (!code || code != this.yzCode || phone != this.yzPhone) {
					this.$u.toast('验证码不正确');
					return;
				}
				var userid = this.$store.state.userid
				const {data:res} = await this.$Request({
					url:'apis/home/Withdraw/bangZ?userid=' + userid + '&zhifuname=' + aliName + '&zhifucount=' + aliNum
				})
				
				if (res && res.code == 200) {
					this.$u.toast('设置成功');
					setTimeout(()=>{
						uni.navigateBack()
					},1000)
				} else {
					this.$u.toast('设置失败');
				}
			},
			codeChange(text) {
				this.codeText = text;
			},
			async getCode() {
				var code = Math.floor(Math.random() * (999999 - 100000 + 1) + 100000);
				if(this.$refs.uCode.canGetCode) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					const {data:res} = await this.$Request({
						url: 'api/code/sms',
						data:{
							phone: this.phone,
							code: code
						}
					})
					if (res && res.code == 200) {
						this.yzPhone = this.phone;
						this.yzCode = code;
						uni.hideLoading();
						this.$u.toast('发送成功');
						this.$refs.uCode.start();
					}
				}else {
					this.$u.toast('倒计时结束后再发送');
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100vh;
		background-color: #2A2931;
		.fieldbox{
			margin: 20rpx;
			/deep/.u-label-text{
				color: rgb(213, 157, 81);
			}
			/deep/input{
				color: #fff!important;
			}
		}
	}
	
</style>
